import { defineStore } from 'pinia'

export const useUserStore = defineStore('user', {
  state: () => ({
    userId: null,
    username: '',
    token: '',
    isAuthenticated: false
  }),

  actions: {
    setUser(userData) {
      this.userId = userData.id
      this.username = userData.username
      this.token = userData.token
      this.isAuthenticated = true
    },

    clearUser() {
      this.userId = null
      this.username = ''
      this.token = ''
      this.isAuthenticated = false
    }
  },

  persist: {
    enabled: true,
    strategies: [
      {
        key: 'user',
        storage: localStorage
      }
    ]
  }
})